module.exports = function ($resource, $state, $http, $q, $scope, FileUploader, $modal, toaster, $stateParams) {
  /* 分页
* ========================================= */
$scope.maxSize = 5;             //最多显示多少个按钮
$scope.bigCurrentPage = 1;      //当前页码
$scope.itemsPerPage = 10         //每页显示几条
$scope.obj={};
$scope.d={};
$scope.searchform = {};
$scope.type = $stateParams.type;
console.log($state.params.type);
$scope.getCompanyInfo = function () {
  $resource('/api/ac/ggc/reviewCompanyService/getApplyCompanyInfo', {}, {}).save({}, function(res){
      if(res.errcode != 0){ 
          toaster.error({title:"",body:res.errmsg});
          return;
      }
      console.log('查询企业信息是否完整');
      console.log(res);
      if (res.data.msg == '0') {
        if (confirm('请先完善企业信息')) {
          $state.go('app.completeinfo');
        } else {
          $state.go('app.completeinfo');
        }
      }
  });
}
$scope.getCompanyInfo();
$scope.pageChanged = function () {
    var para = {
        pageNo:$scope.bigCurrentPage,
        pageSize:$scope.itemsPerPage,
    };
    para = angular.extend($scope.searchform, para);
    $resource('/api/as/ggc/reviewCompanyProject/findInfoList', {}, {}).save(para, function(res){	
        if(res.errcode === 0){
            $scope.a = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
        }else{
            alert(res.errmsg);
        }
    });
};
$scope.pageChanged();

$scope.search=function(){
    var dic = {
        pageNo:$scope.currentPage,
        pageSize:$scope.itemsPerPage,
    }
    $resource('', {}, {}).save(dic, function(res){
        if(res.errcode === 0 || res.errcode === 10003){
            $scope.a=res.data.results;
            console.log($scope.a);
            $scope.totalItems = res.data.totalRecord;
        }else{
            alert(res.errmsg);
        }
    });
}

$scope.toinfo= function (info) {
    $scope.type = 'onlyinfo';	
    var modalInstance = $modal.open({
      template: require('../views/projectinfo.html'),
      controller: 'projectinfo',
      size: 'lg',
      resolve: {
        items: function () {
          return info;
        },
        type: function () {
          return $scope.type;
        }
      }
    });
    modalInstance.result.then(function (showResult) {	
        $scope.pageChanged();
    });
}

// 上传材料
$scope.upload= function (item) {
    var modalInstance = $modal.open({
      template: require('../views/upload_document.html'),
      controller: 'upload_document',
      size: 'lg',
      resolve: {
        items: function () {
          return item;
        }
      }
    });
    modalInstance.result.then(function (showResult) {	
        $scope.pageChanged();
    });
}
// 编辑
$scope.edit= function (item) {
  var modalInstance = $modal.open({
    template: require('../views/project_edit.html'),
    controller: 'project_edit',
    size: 'lg',
    resolve: {
      items: function () {
        return item;
      }
    }
  });
  modalInstance.result.then(function (showResult) {	
      $scope.pageChanged();
  });
}
// 提交申报
$scope.submit = function(item){
    if (confirm('是否申报该项目?')){
        if (item.project_file) {
            var filearr = JSON.parse(item.project_file);
            console.log(JSON.parse(item.project_file))
            if (item.project_build == '0'){
              console.log('建筑类');
              if (filearr.aa == undefined){
                alert('请上传沈阳市旅游发展专项资金申报文本');
                return;
              }
              if (filearr.bb == undefined){
                alert('请上传项目建设可行性研究报告');
                return;
              } 
              if (filearr.cc == undefined){
                alert('请上传符合所在地区旅游总体规划证明');
                return;
              } 
              if (filearr.dd == undefined){
                alert('请上传发改部门项目核准或备案文件');
                return;
              } 
              if (filearr.ee == undefined){
                alert('请上传规划选址意见书/项目用地预审意见/国有土地使用权出让合同');
                return;
              } 
              if (filearr.ff == undefined){
                alert('请上传项目建设资金材料');
                return;
              } 
              if (filearr.gg == undefined){
                alert('请上传营业执照（副本）复印件');
                return;
              } 
              if (filearr.hh == undefined){
                alert('请上传上年度财务审计报告（验资报告、完税证明等)');
                return;
              }  
              if (filearr.ii == undefined){
                alert('请上传要求提供的其他文件');
                return;
              }  
              $resource('/api/ac/ggc/reviewCompanyProjectService/updateApply', {}, {}).save({'project_code' : item.project_code}, function(res){
                  if(res.errcode != 0){
                    toaster.error({title:"",body:res.errmsg});
                    return;
                  }
                  toaster.success({title:"",body:'申报成功'});
                  $scope.pageChanged();
              });
            } else if (item.project_build == '1'){
                console.log('非建筑类');
                if (filearr.aa == undefined){
                  alert('请上传沈阳市旅游发展专项资金申报文本');
                  return;
                }
                if (filearr.bb == undefined){
                  alert('请上传项目建设可行性研究报告');
                  return;
                } 
                if (filearr.ff == undefined){
                  alert('请上传项目建设资金材料');
                  return;
                } 
                if (filearr.gg == undefined){
                  alert('请上传营业执照（副本）复印件');
                  return;
                } 
                if (filearr.hh == undefined){
                  alert('请上传上年度财务审计报告（验资报告、完税证明等)');
                  return;
                }  
                if (filearr.ii == undefined){
                  alert('请上传要求提供的其他文件');
                  return;
                } 
                $resource('/api/ac/ggc/reviewCompanyProjectService/updateApply', {}, {}).save({'project_code' : item.project_code}, function(res){
                    if(res.errcode != 0){
                      toaster.error({title:"",body:res.errmsg});
                      return;
                    }
                    toaster.success({title:"",body:'申报成功'});
                    $scope.pageChanged();
                });
    
            }
        } else {
          alert('请上传相关资料');
        }
        
    }
}

// 监听
//   $scope.$watch('productflag', function(){
//     $scope.pageChanged();
//   }, true)

}
